package reflect;

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 练习调用属性
 */

public class Text {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {

        /*
           利用反射机制实例化Student(无参与有参)，并输出
         */

        Student s = new Student();
        System.out.println(s);


        Class cls = Class.forName("reflect.Student");
        Constructor c = cls.getConstructor(int.class,String.class,String.class,int.class);
        Object o = c.newInstance(2,"zhangsna","男",20);
        System.out.println(o);



        Class clss = Class.forName("reflect.Student");
        Object c1 = clss.newInstance();
        System.out.println(c1);

    }
}
